package com.yinxianren.main.study.sync;

public class DemoSynchronizedOne implements Runnable{

    Object lock= new Object();

    @Override
    public void run() {

        synchronized (lock){

            System.out.println(Thread.currentThread().getName()+": 开始执行！");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+": 执行结束！");

        }

    }
}

class MainOne{

    public static void main(String[] args) {
        DemoSynchronizedOne dsn= new DemoSynchronizedOne();
        Thread  t1= new Thread(dsn);
        Thread t2 = new Thread(dsn);
        t1.start();
        t2.start();

        while (t1.isAlive() || t2.isAlive()){

        }

        System.out.println("主程序执行完毕！");


    }
}